<?php
if(!interface_exists('XClassRegister', false)){
	require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'XClassRegister.php');
}
if(!class_exists('XClassRegistry', false)){
	require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'XClassRegistry.php');
}
if(!class_exists('XAnnotation', false)){
	require(XFRAMEWORK_DIR.'/core/annotation/XAnnotation.php');
}
final class XAnnotationClassRegister implements XClassRegister{
	private static $instance = null;

	private function __construct() {
	
	}
	
	/** 
	 * @return XAnnotationClassRegister
	 */	
	static function singleton() {
		if (!self::$instance) {
			self::$instance = new self;
		}
		return self::$instance;
	}
		
	public function register($class){
		$annotation = XAnnotation::singleton($class)->annotations();
		foreach(XClassRegistry::types() as $type){
			if(!isset($annotation[$type])){
				continue;
			}
			XClassRegistry::singleton()->register($type, $class, $annotation[$type]);
		}
		return $this;
	}
}
?>